#!/usr/bin/env python

import sys
import re

matches = []

#def sortby(x):
#   return int(x)[1][1:])

def main():

   if len(sys.argv) == 3:

      f = open(sys.argv[1])

      for line in f:

         if line.startswith('DSC'):

            if re.search(sys.argv[2], line):

               if line.split(',')[1] not in matches:
                  matches.append(line.split(',')[1])

      matches.sort(key = int)

      correction = 0
      j = matches.index(str(84))
      #for i in range(int(matches[0]) / 3, len(matches)):
      for i in range(84 / 3, len(matches)):

         if (i - (84 / 3)) % 5 == 0:
            print

         if (i * 3) == int(matches[j]):
            print i * 3, int(matches[j])
            j+= 1
         else:
            print i * 3, '-'


   else:

      print("Usage: %s tdifile pattern" % sys.argv[0])

if __name__ == "__main__":
   main()
